package com.game.HandleData;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.game.NioSocket.Gsocket;
import com.game.user.User;
import com.game.user.userTalk;

/**
 * data 的应用逻辑处理
 * @author chenlei
 *
 */
public class IallHandleData {
	public User user=null;
	private userTalk talk=null;
	private byte[] pack=null;
	private ExecutorService pool=Executors.newFixedThreadPool(6);
	
	public IallHandleData(){
		System.out.println("创建IallHandleData。。。。。。");
		user=new User();
		talk=new userTalk();
		user.setName("123");//TEST
		User.userOnLine.add(user);
	}

	public void dataHandle(final Gsocket socket){
		user.setSocket(socket);
		while(!socket.getHandleBuffers().isEmpty()){
			pack=socket.getHandleBuffers().poll();
		}
		pool.execute(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				Analysis(user,pack);
			}
		});
	}
	/**
	 * 解析数据
	 */
	public void Analysis(User user,byte[] pack){
		byte  type1=pack[0];
		if(type1==3){//聊天
			talk.Talk(user, pack);	
		}
	}
	
	public Object clone(){
		try {
			user=(User) super.clone();
		
		
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return user;
	}
		
}
